# -*-coding:utf-8 -*-
from django.db import models


class MenuType(models.Model):
    name = models.CharField(max_length=30)
    icon = models.CharField(max_length=20)
    seq = models.IntegerField()
    
class Menu(models.Model):
    name = models.CharField(max_length=30)
    icon = models.CharField(max_length=20)
    operation_function = models.CharField(max_length=20)
    menu_type = models.ForeignKey(MenuType)
    seq = models.IntegerField();
    
class Role(models.Model):
    name = models.CharField(max_length=30)
    description = models.CharField(max_length=100)
    menus = models.ManyToManyField(Menu)
    
    
class User(models.Model):
    name = models.CharField(max_length=30)
    password = models.CharField(max_length=30)
    activable = models.BooleanField()
    roles = models.ManyToManyField(Role)
    insert_date = models.DateField()
    
class Contact(models.Model):
    oftype = models.CharField(max_length=5)
    code = models.CharField(max_length=100,unique=True)
    name = models.CharField(max_length=100)
    address = models.CharField(max_length=200,null=True)
    phone = models.CharField(max_length=50,null=True)
    fax = models.CharField(max_length=50,null=True)
    person = models.CharField(max_length=10,null=True)
    
class ContainerType(models.Model):
    size = models.CharField(max_length=30)
    max_weigth = models.IntegerField(null=True)
    max_volume = models.IntegerField(null=True)
    
class Currency(models.Model):
    code = models.CharField(max_length=5)
    rate = models.DecimalField(max_digits=7,decimal_places=3)
    
class Feetype(models.Model):
    code = models.CharField(max_length=10)
    name = models.CharField(max_length=20)
    default_currencytype = models.ForeignKey(Currency)
    
class Country(models.Model):
    code = models.CharField(max_length=30)
    name = models.CharField(max_length=30)
    phone = models.CharField(max_length=20)

class Port(models.Model):
    code = models.CharField(max_length=20)
    name = models.CharField(max_length=50)
    
#包装类型
class PackType(models.Model):
    code = models.CharField(max_length=20)
    name = models.CharField(max_length=50)
    
class Orders(models.Model):
    order_code = models.CharField(max_length=30) #单号,也是hbl单号
    mbl_code = models.CharField(max_length=30,null=True)
    container_type = models.IntegerField(null=True) #FCL LCL
    saleman = models.ForeignKey(User,related_name='+')
    operator = models.ForeignKey(User,related_name='+')
#    client_code = models.ForeignKey(Contact,blank=True, null=True, on_delete=models.SET_NULL)
    client_code = models.CharField(max_length=10)
    client_company = models.CharField(max_length=50,null=True)
    client_person = models.CharField(max_length=10,null=True)
    client_phone = models.CharField(max_length=20,null=True)
    client_fax = models.CharField(max_length=20,null=True)
    cargo_collection_type = models.IntegerField(null=True) #自揽,指定
    cargo_collection_code = models.CharField(max_length=10,null=True)
    cargo_collection_name = models.CharField(max_length=50,null=True)
    shipper = models.CharField(max_length=100,null=True)
    consignee = models.CharField(max_length=100,null=True)
    notifier = models.CharField(max_length=100,null=True)
    receipt_place = models.CharField(max_length=20,null=True) #收货地
    loading_port = models.CharField(max_length=20,null=True)  #起运港
    unloading_port = models.CharField(max_length=20,null=True)#卸运港
    destination_port = models.CharField(max_length=20,null=True) #目的港
    destination_place = models.CharField(max_length=20,null=True) #目的地
    container_info = models.CharField(max_length=50,null=True) #集装箱信息
    large_number = models.IntegerField(null=True)
    large_packing_type = models.CharField(max_length=10,null=True)
    small_number = models.IntegerField(null=True)
    small_packing_type = models.CharField(max_length=10,null=True)
    gross_weight =models.DecimalField(max_digits=7,decimal_places=3,null=True)
    volume = models.DecimalField(max_digits=7,decimal_places=3,null=True)
    chinese_name = models.CharField(max_length=50,null=True)
    english_name = models.CharField(max_length=50,null=True)
    shipping_mark = models.CharField(max_length=20,null=True) #唛头
    info_summy = models.CharField(max_length=70,null=True) #信息总计
    booking_date = models.DateField(null=True)
    shipping_date = models.DateField(null=True)
    arrival_date = models.DateField(null=True)
    m_payment_type = models.CharField(max_length=10,null=True)
    h_payment_type = models.CharField(max_length=10,null=True)
    shipping_company_code = models.CharField(max_length=20,null=True)
    shipping_company_name = models.CharField(max_length=50,null=True)
    shipping_company_person = models.CharField(max_length=10,null=True)
    shipping_company_phone = models.CharField(max_length=20,null=True)
    shipping_company_fax = models.CharField(max_length=20,null=True)
    booking_proxy_company_code = models.CharField(max_length=20,null=True)
    booking_proxy_company_name = models.CharField(max_length=50,null=True)
    booking_proxy_company_person = models.CharField(max_length=10,null=True)
    booking_proxy_company_phone = models.CharField(max_length=20,null=True)
    booking_proxy_company_fax = models.CharField(max_length=20,null=True)
    h_release_way = models.IntegerField(null=True)
    m_release_way = models.IntegerField(null=True)
    remark = models.TextField(null=True)
    status = models.IntegerField() #订单状态位
    insert_date = models.DateTimeField()
    update_date = models.DateTimeField()
    
    
class OrderHbl(models.Model):
    order = models.OneToOneField(Orders)
    lading_bill_way = models.CharField(max_length=30,null=True)
    shipper = models.CharField(max_length=200,null=True)
    consignee = models.CharField(max_length=200,null=True)
    notifier = models.CharField(max_length=200,null=True)
    cargo_collection_name = models.CharField(max_length=100,null=True)
    so = models.CharField(max_length=30,null=True)
    shipping_date = models.DateField(null=True)
    shipping_name_number = models.CharField(max_length=50,null=True) #船名/航次
    receipt_place = models.CharField(max_length=20,null=True) #收货地
    loading_port = models.CharField(max_length=20,null=True)  #起运港
    unloading_port = models.CharField(max_length=20,null=True)#卸运港
    destination_port = models.CharField(max_length=20,null=True) #目的港
    destination_place = models.CharField(max_length=20,null=True) #目的地
    transit_clause = models.CharField(max_length=50,null=True) #运输条款
    payment_way = models.CharField(max_length=30,null=True) #付款方式
    container_info = models.CharField(max_length=50,null=True) #箱量信息
    fee_description = models.CharField(max_length=50,null=True) #费用说明
    info_summy = models.CharField(max_length=70,null=True) #信息总计
    numbers = models.IntegerField(null=True) #件数
    packing_type = models.CharField(max_length=10,null=True) #包装类型
    gross_weight = models.DecimalField(max_digits=11,decimal_places=3,null=True) #毛重
    volume = models.DecimalField(max_digits=11,decimal_places=3,null=True) #体积
    payment_address = models.CharField(max_length=50,null=True)
    issue_number = models.CharField(max_length=20,null=True)#签发张数
    issue_address = models.CharField(max_length=50,null=True)#签发地点
    issue_date = models.DateField(null=True)#签发日期
    sealing_number = models.CharField(max_length=50,null=True)#封箱号
    shipping_mark = models.CharField(max_length=50,null=True)#唛头
    english_name = models.CharField(max_length=50,null=True)#英文品名
    
class OrderMbl(models.Model):
    order = models.OneToOneField(Orders)
    lading_bill_way = models.CharField(max_length=30,null=True)#提单方式
    booking_number = models.CharField(max_length=30,null=True)#订舱编号
    mbl_code = models.CharField(max_length=30,null=True)#Mbl编号
    shipper = models.CharField(max_length=200,null=True)
    consignee = models.CharField(max_length=200,null=True)
    notifier = models.CharField(max_length=200,null=True)
    cargo_collection_name = models.CharField(max_length=200,null=True)
    so = models.CharField(max_length=30,null=True)
    shipping_date = models.DateField(null=True)
    shipping_name_number = models.CharField(max_length=50,null=True) #船名/航次
    receipt_place = models.CharField(max_length=20,null=True) #收货地
    loading_port = models.CharField(max_length=20,null=True)  #起运港
    unloading_port = models.CharField(max_length=20,null=True)#卸运港
    destination_port = models.CharField(max_length=20,null=True) #目的港
    destination_place = models.CharField(max_length=20,null=True) #目的地
    transit_clause = models.CharField(max_length=50,null=True) #运输条款
    payment_way = models.CharField(max_length=30,null=True) #付款方式
    container_info = models.CharField(max_length=50,null=True) #箱量信息
    fee_description = models.CharField(max_length=50,null=True) #费用说明
    info_summy = models.CharField(max_length=70,null=True) #信息总计
    numbers = models.IntegerField(null=True) #件数
    packing_type = models.CharField(max_length=10,null=True) #包装类型
    gross_weight = models.DecimalField(max_digits=11,decimal_places=3,null=True) #毛重
    volume = models.DecimalField(max_digits=11,decimal_places=3,null=True) #体积
    payment_address = models.CharField(max_length=50,null=True)
    issue_number = models.CharField(max_length=20,null=True)#签发张数
    issue_address = models.CharField(max_length=50,null=True)#签发地点
    issue_date = models.DateField(null=True)#签发日期
    sealing_number = models.CharField(max_length=50,null=True)#封箱号
    shipping_mark = models.CharField(max_length=50,null=True)#唛头
    english_name = models.CharField(max_length=50,null=True)#英文品名
    
class Bill(models.Model):
    order = models.ForeignKey(Orders)
    bill_code = models.CharField(max_length=10)
    bill_name = models.CharField(max_length=20)
    amount= models.DecimalField(max_digits=11,decimal_places=2)#单价
    count =models.DecimalField(max_digits=11,decimal_places=3,null=True)#数量
    total= models.DecimalField(max_digits=11,decimal_places=2,default=0.00)#总价
    currency = models.CharField(max_length=10)#币种
    type = models.IntegerField(default=1)#1公司成本,2是对外账单
    
    